package diploma.kisel.modelas.service;

import java.util.List;

import diploma.kisel.modelas.domain.DeviceType;
import diploma.kisel.modelas.repository.DeviceTypeRepositoryImpl;
import diploma.kisel.modelas.repository.api.DeviceTypeRepository;
import diploma.kisel.modelas.service.api.DeviceTypeService;

public class DeviceTypeServiceImpl implements DeviceTypeService{
	
	private DeviceTypeRepository deviceTypeRepository = new DeviceTypeRepositoryImpl();

	@Override
	public List<DeviceType> findAll() {
		return deviceTypeRepository.findAll();
	}

	@Override
	public DeviceType findById(String name) {
		if (name!=null && !name.equals(""))
			return deviceTypeRepository.findById(name);
		else 
			return null;
	}

	@Override
	public DeviceType save(DeviceType type) {
		if (type.getId()!=null && !type.getId().equals(""))
			return deviceTypeRepository.save(type);
		else
			return null;
	}

	@Override
	public void remove(DeviceType type) {
		if (type.getId()!=null && !type.getId().equals(""))
			deviceTypeRepository.remove(type);		
	}

	@Override
	public void remove(String id) {
		DeviceType type = deviceTypeRepository.findById(id);
		deviceTypeRepository.remove(type);		
	}

	@Override
	public DeviceType update(DeviceType type) {
		if (type.getId()!=null && !type.getId().equals(""))
			return deviceTypeRepository.update(type);
		else
			return null;
	}

}
